package com.desaysv.mvp

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

/**
 * @author linzi
 * @date 2022-11-11
 */
abstract class MVPActivity<T : IView, E : IModel, K : BasePresenter<T, E>> : AppCompatActivity(),
    IView {
    /****MVP相关start****/
    abstract fun setPresenter(): K?
    private var presenter: K? = null
    fun getPresenter(): K? {
        if (presenter == null) {
            presenter = setPresenter()
        }
        return presenter
    }

    /****MVP相关end****/

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        /****MVP相关start****/
        getPresenter()?.attach(this)
        /****MVP相关end****/
    }

    override fun onDestroy() {
        super.onDestroy()
        /****MVP相关start****/
        presenter?.onDestory()
        presenter = null
        /****MVP相关end****/
    }
}